﻿using DotNetCore.CAP;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;

namespace SHKF.B2C.Cap
{
    public static class HostedExtensions
    {
        public static IServiceCollection AddCap(this IServiceCollection services, IConfiguration configuration)
        {

            services.Configure<RabbitMQOptions>(configuration.GetSection("RabbitMQOptions"));
            string connection = configuration.GetSection("MsSqlConnection").Value;
            services.AddCap(x =>
            {
                //存储消息数据
                x.UseSqlServer(configure =>
                {
                    configure.ConnectionString = connection;
                    configure.UseSqlServer2008();
                });

                //configuration
                RabbitMQOptions rabbitMQ = configuration.GetSection("RabbitMQOptions").Get<RabbitMQOptions>();
                x.UseRabbitMQ((options) =>
                {
                    options = rabbitMQ;
                });

                x.FailedRetryCount = 10;        //失败后重试次数
                x.FailedRetryInterval = 60;     //重试间隔
              
                x.UseDashboard();
            });

            return services;
        }

    }
}
